#include <cstdio>
#include <cstring>

#define MAXN 500+5
int N, K;
int G[MAXN][MAXN];
bool book[MAXN];
int match[MAXN];

bool dfs(int n) {
	for (int i=1; i<=N; i++) {
		if (G[n][i] == 1 && !book[i]) {
			book[i] = true;
			if (match[i]==0 || dfs(match[i])) {
				match[i] = n;
				return true;
			}
		}
	}
	return false;
}

int main() {
	while (~scanf("%d%d", &N, &K)) {
		memset(G, 0, sizeof(G));
		for (int i=1; i<=K; i++) {
			int R, C;
			scanf("%d%d", &R, &C);
			G[R][C] = 1;
		}
		int cnt = 0;
		memset(match, 0, sizeof(match));
		for (int i=1; i<=N; i++) {
			memset(book, 0, sizeof(book));
			if (dfs(i)) cnt++;
		}
		printf("%d\n", cnt);
	}
	return 0;
}
